<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }

        .uploader-list {
            margin-left: -15px;
        }

        .uploader-list .info {
            position: relative;
            margin-top: -25px;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 100px;
            height: 25px;
            text-align: center;
            display: none;
        }

        .uploader-list .handle {
            position: relative;
            background-color: black;
            color: white;
            filter: alpha(Opacity=80);
            -moz-opacity: 0.5;
            opacity: 0.5;
            width: 120px;
            text-align: right;
            height: 18px;
            margin-bottom: -18px;
            display: none;
        }

        .uploader-list .handle i {
            margin-right: 5px;
        }

        .uploader-list .handle i:hover {
            cursor: pointer;
        }

        .uploader-list .file-iteme {
            margin: 12px 0 0 15px;
            padding: 1px;
            float: left;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">客户昵称</label>
        <div class="layui-input-block">
            <input type="text" name="memberName" lay-verify="required" lay-reqtext="昵称不能为空" placeholder="请输入昵称" value=""
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">关联实体卡号</label>
        <div class="layui-input-block">
            <input type="text" name="memberNum" lay-reqtext="" placeholder="请输入关联实体卡号"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label required">电话号码</label>
        <div class="layui-input-block">
            <input type="text" name="phone" lay-verify="required|phone" lay-reqtext="电话号码不能为空" placeholder="请输入电话号码"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item" style="width:800px;">

        <label class="layui-form-label">有效时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="effectTime" name="effectTime" placeholder="yyyy-MM-dd HH:mm:ss">
        </div>
    </div>


    <!--    <div class="layui-form-item" style="width:800px;">-->
    <!--        <label class="layui-form-label">充值金额(元)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="text" name="chongzhi" lay-verify="" value="0" placeholder="请输入充值金额(默认为0)" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->

    <!--    <div class="layui-form-item" style="width:800px;">-->
    <!--        <label class="layui-form-label">剪发次数(次)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="text" name="jianfacount" lay-verify="" value="0" placeholder="请输入充值剪发次数(默认为0)" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->


    <!--    <div class="layui-form-item" style="width:800px;">-->
    <!--        <label class="layui-form-label">干洗次数(次)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="text" name="ganxicount" lay-verify="" value="0" placeholder="请输入充值干洗次数(默认为0)" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->


    <!--    <div class="layui-form-item" style="width:800px;">-->
    <!--        <label class="layui-form-label">干洗次数(次)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="text" name="ganxicount" value="0"  placeholder="请输入充值干洗次数(默认为0)" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->
    <!--    <div class="layui-form-item" style="width:800px;">-->
    <!--        <label class="layui-form-label">洗发次数(次)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="text" name="xifacount" value="0"  placeholder="请输入充值洗发次数(默认为0)" class="layui-input">-->
    <!--        </div>-->
    <!--    </div>-->


    <div class="layui-form-item" style="width:800px;">
        <label class="layui-form-label">会员卡种类</label>
        <div class="layui-input-block">
            <select name="memberRank" id="sellState" lay-filter="">
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'upload', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            laydate = layui.laydate,
            $ = layui.$;


        laydate.render({
            elem: '#effectTime',
            type: 'datetime',
            trigger: 'click'    // 就是这个属性
        });


        $.ajax({
            type: "POST", //提交方式
            url: "../barItem/listNoPage",//路径
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {//返回数据根据结果进行相应的处理
                if (result.code == "0" && result.data) {
                    $("#sellState").html("")
                    var html = '<option value="">请选择</option>';
                    $.each(result.data, function (index, item) {
                        html += '<option value="' + item.consumptionItems + '">' + item.consumptionItems + '</option>';
                    })
                    $("#sellState").html(html)
                    form.render('select')
                } else {
                    layer.msg(result.msg);
                }
            }
        });


        //自定义验证规则
        form.verify({
            email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
            , qq: [/^[1-9][0-9]{4,11}$/, '请输入正确的QQ号码']
            , phone: [
                /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
                , '请输入正确的手机号'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });
        var iframeIndex = parent.layer.getFrameIndex(window.name);

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.addMember = localStorage.getItem("memberId");
            $.ajax({
                type: "POST", //提交方式
                url: "save",//路径
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),//数据，这里使用的是Json格式进行传输
                dataType: "json",
                success: function (result) {//返回数据根据结果进行相应的处理
                    if (result.code == "200") {
                        var index = layer.msg("添加成功", {
                            time: 200, //如果不配置，默认是3秒）
                        }, function () {
                            // 关闭弹出层
                            layer.close(index);
                            parent.layer.close(iframeIndex);
                            //window.location = "../";
                        })
                    } else {
                        layer.msg(result.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>